<?php
/**
 * Created by PhpStorm.
 * User: yu
 * Date: 2017/1/6
 * Time: 下午4:52
 */

namespace Admin\Controller;

use Common\Controller\AdminController;
use Common\Model\TypeAttrModel;
use Common\Model\TypeModel;

class TypeAttrController extends AdminController
{
	protected $typeAttrModel;
	public function __init(){
		$this->typeAttrModel = new TypeAttrModel();
	}
	public function lists(){
		$tid = I('get.tid');
		$type = (new TypeModel())->find($tid);
		$this->assign('type',$type);
		//获取当前类型属性列表
		$typeAttrList = $this->typeAttrModel->where("tid=$tid")->select();
		$this->assign('typeAttrList',$typeAttrList);
		$this->display();
	}

	public function add(){

		if(IS_POST){
			$this->store($this->typeAttrModel,I('post.'),function(){
				$this->success('操作成功',u('admin/typeAttr/lists',['tid'=>I('get.tid')]));
			});
		}else{
			$tid = I('get.tid');
			$type = (new TypeModel())->find($tid);
			$this->assign('type',$type);
			$this->display();
		}
	}
}